

//引入网络库
import { get, post } from "../../util/util.js"
// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "baomingyiren",
  /**
   * 页面的初始数据
   */

  data: {
    showModal: false,
    uid: '',
    fid: '',
    touid: '',
    rid: '',
    hiddenmodalput: true,
    contentInputStr: '',
    selected1: true,
    selected2: false,
    defaulImg: "http://wolaimage-10029986.image.myqcloud.com/1-2016051421050035278.png"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  onLoad: function (o) {
    var that = this;
    console.log("获取传值===" + o.uid)
    that.setData({
      uid: o.uid,
      fid: o.fid
    })

    post("/film/getFilmSign", { uid: that.data.uid, fid: that.data.fid, status: 1 }).then(data => {
      console.log('film/getFilmSign====================' + JSON.stringify(data.data));
      that.setData({
        daixuan: data.data,
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    
  },


  //以下为自定义点击事件

  //点击待选TAB
  selected1: function (e) {
    var that = this;
    this.setData({
      selected1: true,
      selected2: false,
    })

    post("/film/getFilmSign", { uid: that.data.uid, fid: that.data.fid, status: 1 }).then(data => {
      console.log('film/getFilmSign====================' + JSON.stringify(data.data));
      that.setData({
        daixuan: data.data,
      })
    })
  },
  //点击已选 
  selected2: function (e) {
    var that = this;
    this.setData({
      selected2: true,
      selected1: false,
    })

    post("/film/getFilmSign", { uid: that.data.uid, fid: that.data.fid, status: 4 }).then(data => {
      console.log('film/getFilmSign====================' + JSON.stringify(data.data));
      that.setData({
        yixuan: data.data,
      })
    })
  },
  //加入已选
  addYiXuan: function (e) {
    var that = this;
    var rid = e.currentTarget.dataset.rid;
    var uid = e.currentTarget.dataset.uid;
    post("/film/updateSignStatus", { uid: that.data.uid, rid: rid, sign_uid: uid, status: 4 }).then(data => {
      console.log('film/updateSignStatus====================' + JSON.stringify(data.data));
      post("/film/getFilmSign", { uid: that.data.uid, fid: that.data.fid, status: 1 }).then(data => {
        console.log('film/getFilmSign====================' + JSON.stringify(data.data));
        that.setData({
          caiItems: data.data,
        })
      })
    })
  },
  //回绝
  delYiRen: function (e) {
    var that = this;
    var rid = e.currentTarget.dataset.rid;
    var uid = e.currentTarget.dataset.uid;
    post("/film/updateSignStatus", { uid: that.data.uid, rid: rid, sign_uid: uid, status: 3 }).then(data => {
      console.log('film/updateSignStatus====================' + JSON.stringify(data.data));
      post("/film/getFilmSign", { uid: that.data.uid, fid: that.data.fid, status: 1 }).then(data => {
        console.log('film/getFilmSign====================' + JSON.stringify(data.data));
        that.setData({
          caiItems: data.data,
        })
      })
    })
  },
 
  //点击按钮 指定的hiddenmodalput弹出框  
  modalinput: function (e) {
    var that = this;
    var touid = e.currentTarget.dataset.touid;
    var rid = e.currentTarget.dataset.rid;
    that.setData({
      touid: touid,
      rid: rid,
    })
    post("/pay/getPayItem", { cate: 1 }).then(data => {
      var item_id = data.data.id;
      post("/pay/payItem", { item_id: data.data.id, uid: that.data.uid }).then(data1 => {
        if (data1.code == 0) {// 
          that.setData({
            hiddenmodalput: !that.data.hiddenmodalput,
          })

        } else if (data1.code == 4011) {
          wx.navigateTo({
            url: '../pay/pay?uid=' + that.data.uid,
          })
        }
      })
    })
  },
  //取消按钮  
  cancel: function () {
    var that = this;
    that.setData({
      hiddenmodalput: true,
      contentInputStr: '',
      touid: '',
      rid: '',
    });
  },
  //确认  
  confirm: function () {
    var that = this;
    that.setData({
      hiddenmodalput: true,
      showModal: true
    })
  },
  //获取用户输入的用户名
  contentInput: function (e) {
    var that = this;
    that.setData({
      contentInputStr: e.detail.value
    })
  },
  /**
     * 弹窗
     */
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    var that = this;
    post("/message/sendInvite", {
      uid: that.data.uid,
      touid: that.data.touid,
      rid: that.data.rid,
      content: that.data.contentInputStr
    }).then(data => {
      if (data.code == 0) {
        that.setData({
          // hiddenmodalput: true,
          name: that.data.contentInputStr,
          contentInputStr: '',
          touid: '',
          rid: '',
          showModal: true
        })
        this.hideModal();
        wx.showToast({
          title: '邀请试戏已发送',
          icon: 'success',
          duration: 1200
        })
      }
    })
  },
  calling: function (e) {
    var phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  }
})

